package graduate.wangyaqi.OnlyQuestions;

import graduate.wangyaqi.FillingQuestions.FillingQuestions;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class OnlyQuestionsService {
    @Resource
    private OnlyQuestionsRepository onlyQuestionsRepository;

    //保存数据
    @Transactional
    public void save(OnlyQuestions onlyQuestion) {
        onlyQuestionsRepository.save(onlyQuestion);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        onlyQuestionsRepository.deleteById(id);
    }

    //查询数据
    @Transactional
    public Iterable<OnlyQuestions> getAll() {
        Iterable<OnlyQuestions> onlyQuestions = onlyQuestionsRepository.findAll();
        return onlyQuestions;
    }
    @Transactional
    public Iterable<OnlyQuestions> getAllByTaotiID(long id){
        Iterable<OnlyQuestions> onlyQuestions = onlyQuestionsRepository.findAllByTaotiID(id);
        return onlyQuestions;
    }
    @Transactional
    public Optional<OnlyQuestions> findById(Long aLong){
        return onlyQuestionsRepository.findById(aLong);
    };

    @Transactional
    public int countAllByStuIDadnAndTaotiID(Long taotaoId ){
        return onlyQuestionsRepository.countAllByTaotiID(taotaoId);
    }

    @Transactional
    public OnlyQuestions getFirstByTaotiIDAndIdIsGreaterThan(long taotiId, long id){
        return onlyQuestionsRepository.getFirstByTaotiIDAndIdGreaterThan(taotiId,id);
    }

    @Transactional
    public OnlyQuestions getFirstByTaotiIDAndIdIsLessThan(long taotiId, long id){
        return onlyQuestionsRepository.getFirstByTaotiIDAndIdLessThanOrderByIdDesc(taotiId,id);
    }
}
